//
//  TTNeedFullViewController.m
//  iNeedish
//
//  Created by Felipe Navarro V. on 28-10-09.
//  Copyright 2009 deis. All rights reserved.
//

#import "TTNeedFullViewController.h"
#import "NeedHelpsViewDataSource.h"
#import "NeedsViewDataSource.h"

#import "NeedHelpsResultsModel.h"
#import "NeedsModel.h"
#import <QuartzCore/QuartzCore.h>

#import "INDefaultStylesheet.h"


#import "TTTableNeedFullItem.h"
#import "TTTableNeedFullItemCell.h"
#import "TTTableHelpItem.h"
#import "TTTableHelpItemCell.h"
#import "NeedHelpsViewDataSource.h"
#import "NeedHelpsModel.h"
#import "Need.h"
#import "Help.h"

//static CGFloat kImageWidth = 57;
//static CGFloat kImageHeight = 57;
static const CGFloat kSmallMargin = 6;




@implementation TTNeedFullViewController


@synthesize need_id;

- (id)init {
	if (self = [super init]) {
//		_Helps = [[TTTableViewController alloc] init];
		need_id = nil;
	}
	return self;
}



- (void)loadView
{
    // Create the tableview.
	self.variableHeightRows = YES;	
    self.view = [[[UIView alloc] initWithFrame:TTApplicationFrame()] autorelease];
    self.tableView = [[[UITableView alloc] initWithFrame:TTApplicationFrame() style:UITableViewStylePlain] autorelease];
    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:self.tableView];
	[self.tableView reloadData];
    
}	

//- (id<UITableViewDelegate>)createDelegate {
//	return self;//[[[TTTableViewDelegate alloc] initWithController:self] autorelease];
//}

//- (void)createModel {
//	
//	
//	if (!self.dataSource) { 
//		TTLOG(@"MoodEl?");
//		id<TTTableViewDataSource>ds_helps = [NeedHelpsViewDataSource dataSourceWithItems:nil];
//		ds_helps.model = CreateNeedHelpsModelWithCurrentSettings(@"needs", @"view", 20, self.need_id);
//		[ds_helps load:TTURLRequestCachePolicyDefault more:YES];
//		
//		self.dataSource = ds_helps;
//		
//	//	self.dataSource = [TTSectionedDataSource dataSourceWithObjects: 
////						   @"Sign Up", 
////						   @"email", 
////						   @"password", 
////						   @"firstName", 
////						   @"lastName", 
////						   @"Twitter Login", 
////						   nil]; 
//		
//	} 
//	
////	[self.tableView reloadData];
//}

- (id)initWithNeed:(NSString*)need {
//	TTLOG(@"we initWithNeed: %@ ", need);
	if (self = [super init]) {
		self.need_id = need;
		self.hidesBottomBarWhenPushed = YES;
		self.statusBarStyle = UIStatusBarStyleBlackOpaque;
		self.navigationBarTintColor = TTSTYLEVAR(needishBlueColor);
		self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;	
		
		self.title = @"Need";
//*********		
		self.variableHeightRows = YES;
		id<TTTableViewDataSource>ds_helps = [NeedHelpsViewDataSource dataSourceWithItems:nil];
		ds_helps.model = CreateNeedHelpsModelWithCurrentSettings(@"needs", @"view", 20, self.need_id);
		//		
		//		
		[ds_helps load:TTURLRequestCachePolicyDefault more:YES];	  
		self.dataSource = ds_helps;
		[self.tableView reloadData];	
		
//		self.tableView.allowsSelection = FALSE;
//*****				
	}
	
	
	return self;
}



////////////////////////////////////////////////////////////////////////////////////
#pragma mark TTViewController

- (UIImage*)imageForError:(NSError*)error
{
    return [UIImage imageNamed:@"Three20.bundle/images/error.png"];
}

//- (void)didReceiveMemoryWarning 
//{ 
//} 
//
- (void)dealloc	{
	TT_RELEASE_SAFELY(need_id);
    [super dealloc];
}


@end

